# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.su>

_realname=geoalchemy2
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.17.1
pkgrel=2
pkgdesc='Geospatial extension to SQLAlchemy (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://geoalchemy-2.readthedocs.io/'
msys2_repository_url='https://github.com/geoalchemy/geoalchemy2'
msys2_references=(
  'purl: pkg:pypi/geoalchemy2'
)
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-packaging"
         "${MINGW_PACKAGE_PREFIX}-python-shapely"
         "${MINGW_PACKAGE_PREFIX}-python-sqlalchemy")
optdepends=("${MINGW_PACKAGE_PREFIX}-libspatialite: support for SpatiaLite databases")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools-scm")
options=('!strip')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz"
        '0001-geoalchemy2-0.17.1-search-spatialite.patch');
sha256sums=('ff5bbe0db5a4ff979f321c8aa1a7556f444ea30cda5146189b1a177ae5bec69d'
            '13d320aef21f0ea56d6b6d70fc11c22c75e3fbb28e0ecc95da8805dae5ff4bec')

prepare() {
  cd "${_realname}-${pkgver}"

  patch -p1 -i "${srcdir}"/0001-geoalchemy2-0.17.1-search-spatialite.patch

  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=${pkgver}
}

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 COPYING.rst "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/COPYING.rst"
}
